#define _CRT_SECURE_NO_WARNINGS 1

#include <queue>

using namespace std;

class KthLargest {
public:
    KthLargest(int k, vector<int>& nums) {
        _k = k;
        for (auto e : nums)
            add(e);
    }

    int add(int val) {
        _pq.push(val);
        if (_pq.size() > _k) _pq.pop();
        return _pq.top();
    }
private:
    priority_queue<int, vector<int>, greater<int>> _pq;
    int _k;
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */